#!/bin/bash

# 进程名称
PROCESS_NAME="stock_tushare"

# 检查进程是否已经运行
PID=$(pgrep -f "$PROCESS_NAME")

if [ ! -z "$PID" ]; then
    echo "进程 $PROCESS_NAME 已经在运行，PID: $PID"
    echo "请先执行 ./stop.sh 停止进程"
    exit 1
fi

# 检查可执行文件是否存在
if [ ! -f "./$PROCESS_NAME" ]; then
    echo "错误: 可执行文件 $PROCESS_NAME 不存在"
    echo "请先编译: go build -o stock_tushare main.go"
    exit 1
fi

# 启动进程
echo "启动进程 $PROCESS_NAME..."
./$PROCESS_NAME &

# 等待进程启动
sleep 2

# 获取新进程的PID
NEW_PID=$(pgrep -f "$PROCESS_NAME")

if [ ! -z "$NEW_PID" ]; then
    echo "进程启动成功，PID: $NEW_PID"
else
    echo "警告: 进程可能启动失败"
    echo "请检查日志输出"
fi